package com.masterclient.app.businessmodule.minemodule.index.tutor;

import com.eoner.baselib.container.CommonBaseResponse;
import com.eoner.baselib.presenter.ThrowableConsumer;
import com.eoner.baselib.utils.toast.ToastUtil;
import com.masterclient.app.businessmodule.settingmodule.api.SettingHttpService;

import io.reactivex.Observable;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
* Created by TMVPHelper on 2017/07/19
*/
public class MyTutorPresenter extends MyTutorContract.Presenter{

    @Override
    public void getTutorInfo() {
        Observable<CommonBaseResponse<MyTutorBean>> observable = SettingHttpService.getInstance().getMyTutorInfo();
        Disposable disposable = toSubscribe(observable, new Consumer<CommonBaseResponse<MyTutorBean>>() {
            @Override
            public void accept(@NonNull CommonBaseResponse<MyTutorBean> bean) throws Exception {
                if(0 == bean.code){
                    mView.getTutorInfoSuccess(bean.getData());
                }else {
                    mView.getTutorInfoFail(WEB_FAILED_STR);
                }
            }
        }, new ThrowableConsumer(){
            @Override
            public void accept(Throwable o) throws Exception {
                super.accept(o);
                ToastUtil.showToast(WEB_FAILED_STR);
            }
        });
    }
}